﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace client.app.gui2
{
    /// <summary>
    /// Button1.xaml 的交互逻辑
    /// </summary>
    public partial class Button1 : UserControl, IUInput
    {
        public bool StopEvent
        {
            get { return true; }
        }
        public string Text
        {
            get { return tbText.Text; }
            set
            {
                tbText.Text = value;
                this.UpBeginDraw();
            }
        }
        public event RoutedEventHandler Click;

        public Button1()
        {
            InitializeComponent();

            MouseLeftButtonDown += new MouseButtonEventHandler(Button1_MouseLeftButtonDown);
            IsEnabledChanged += new DependencyPropertyChangedEventHandler(Button1_IsEnabledChanged);
        }

        void Button1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            CallMouseEvent(MouseEventType.CLICK, new Point());
        }
        void Button1_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Opacity = IsEnabled ? 1 : .3;
        }

        public void CallMouseEvent(MouseEventType type, Point point)
        {
            if (type == MouseEventType.LEFT_DOWN)
            {
                if (Click != null)
                {
                    Click(this, new RoutedEventArgs());
                }
                this.UpBeginDraw();
            }
        }
    }
}
